home *** CD-ROM | disk | FTP | other *** search
- /*--------------------------------------------------------------------------*/
- /* */
- /* */
- /* ------------ Bit-Bucket Software <no-Inc> */
- /* \ 10001101 / Writers and Distributors of */
- /* \ 011110 / No-Cost<no-tm> Software. */
- /* \ 1011 / */
- /* ------ KopyRong (K) 1987. ALL RIGHTS REVERSED. */
- /* */
- /* */
- /* This module was written by Vince Perriello */
- /* */
- /* */
- /* BinkleyTerm Modem Handler Module */
- /* */
- /* */
- /* This software package is being distributed WITH FULL SOURCE CODE */
- /* with the following conditions: 1) If anything awful happens */
- /* because you use it (or don't use it), you accept full */
- /* responsibility; 2) you don't start making tons of voice calls to */
- /* the authors to complain or make suggestions about enhancements, */
- /* useful or otherwise; 3) you do not reuse this code in commercial */
- /* products without specific permission to do so from the authors; */
- /* 4) If you find any problems you send fixes to the authors for */
- /* inclusion in updates; 5) You find some way to express your */
- /* appreciation for this method of distribution, either by writing */
- /* code or application notes, or just sending along a "Thank You" */
- /* message. */
- /* */
- /* There is copyrighted code in this product. We either wrote it */
- /* ourselves or got permission to use it. Please don't force us to */
- /* pay a lawyer -- have some respect for our motives and don't abuse */
- /* this "license". */
- /* */
- /* */
- /*--------------------------------------------------------------------------*/
-
- #include <stdio.h>
- #include <signal.h>
- #include <ctype.h>
- #include <conio.h>
- #include "com.h"
- #include "xfer.h"
-
- extern struct pointers ctl; /* where all the strings is */
- extern struct baud_str btypes[]; /* the baud numbers, strings */
- extern int caller;
- extern int port_ptr;
- extern int baud;
- extern int un_attended;
- extern int fullscreen;
- extern int cur_event;
-
- int slowmodem = 0;
-
-
- #define FAILURE 0
- #define IGNORE 1
- #define SUCCESS 2
-
- struct resp_str {
- char *resp;
- unsigned disp;
- };
-
- static struct resp_str mdm_resps[] = {
- { "CONNECT", 2 },
- { "RING", 1 },
- { "RRING", 1 },
- { "RINGING", 1 },
- { "BUSY", 0 },
- { "VOICE", 0 },
- { "ERROR", 0 },
- { "OK", 0 },
- { "NO CARRIER", 0 },
- { "NO DIAL TONE", 0 },
- { "DIAL TONE", 0 },
- { NULL, 0 }
- };
-
- static char *response_string = " ";
-
- try_2_connect(phnum)
- char *phnum;
- {
- long t1,timerset();
- int k;
-
- while (!KEYPRESS()) /* get out if key pressed */
- {
- k = dial_modem(phnum);
- if (k || KEYPRESS())
- break;
- t1 = timerset(200);
- while (!timeup(t1) && !KEYPRESS())
- time_release(); /* pause for 2 seconds */
- }
- if (!k)
- {
- status_line("!Connection attempt aborted");
- if (!caller)
- FOSSIL_CHAR();
- mdm_hangup();
- }
- /*scr_printf("\r\n");
- locate_x = wherex();
- locate_y = wherey();*/
- }
-
- try_1_connect(phnum)
- char *phnum;
- {
- long t1,timerset();
- int k;
-
- if (!dial_modem(phnum))
- {
- mdm_hangup();
- }
- /* scr_printf("\r\n");
- locate_x = wherex();
- locate_y = wherey();*/
- }
-
- dial_modem(number)
- char *number;
- {
- long t;
- extern long timerset();
-
- if (*number == '\"') /* If it's a script */
- return(do_script(number)); /* then do it that way */
-
- status_line(":Dialing %s",number);
- if (un_attended && fullscreen)
- {
- gotoxy (69, 7);
- cprintf ("%-2d Dialing", cur_event + 1);
- }
-
- DTR_OFF(); /* drop DTR to reset modem */
- timer(20); /* leave it down 2 seconds */
- DTR_ON(); /* then raise DTR again */
- timer(5); /* and wait .5 sec for modem */
- mdm_cmd_char(CR); /* clean up any mess */
- mdm_cmd_string(ctl.predial,0); /* transmit the dial prefix */
- mdm_cmd_string(number,0); /* then the phone number */
- mdm_cmd_string(ctl.postdial,0); /* finally the dial suffix */
- mdm_cmd_char(CR); /* terminate the string */
- CLEAR_INBOUND();
- if (modem_response(7500)) /* we got a good response, */
- {
- timer(20); /* wait for other side */
- return(CARRIER); /* Carrier should be on now */
- }
- return(0); /* no good */
- }
-
- char *get_response(end_time)
- long end_time; /* timeout parameters */
- {
- char *p = response_string; /* points to character cell */
- char c; /* current modem character */
- int count = 0; /* count of characters */
- while ((count < 20) /* until we have 20 chars, */
- && (!timeup(end_time)) /* or out of time, */
- && (!KEYPRESS())) /* or user gets impatient */
- {
- if (!CHAR_AVAIL()) /* if nothing ready yet, */
- {
- time_release();
- continue; /* just process timeouts */
- }
- c = MODEM_IN(); /* get a character */
- if (c == '\r' || c == '\n') /* if a line ending */
- {
- if (count != 0) /* and we have something, */
- break; /* get out */
- else
- continue; /* otherwise just keep going */
- }
- *p++ = c; /* store the character */
- ++count; /* increment the counter */
- }
- *p = '\0'; /* terminate the new string */
-
- if (count != 0)
- {
- fancy_str(response_string); /* make it pretty */
- status_line("\#%s",response_string); /* pop it out on the screen */
- }
-
- return(response_string); /* return the pointer */
- }
-
- parse_response(response)
- char *response;
- {
- char *p; /* temp character pointer */
- register int i; /* array pointer */
- for (i = 0; mdm_resps[i].resp != NULL; i++) /* scan through array */
- {
- p = mdm_resps[i].resp; /* point at possible response*/
- if (strnicmp(response,p,strlen(p)) == 0)/* if a match, */
- return(mdm_resps[i].disp); /* return disposition of it */
- }
- return(1); /* ignore all unknowns */
- }
-
-
- modem_response(ths)
- int ths; /* millisecs to wait */
- {
- long end_time; /* holds time at end of 2min */
- extern long timerset();
-
- char *response; /* pointer to modem response */
- char *c,*skip_blanks(); /* miscellaneous pointer */
- int result = IGNORE; /* result code */
-
- end_time = timerset(ths); /* arm the timeout */
- while ((result == IGNORE) /* until success or failure, */
- && (!timeup(end_time)) /* or out of time, */
- && (!KEYPRESS())) /* or user gets impatient */
- {
- response = get_response(end_time); /* get a response */
- result = parse_response(response); /* parse, determine status */
- time_release();
- }
-
- if (result == SUCCESS) /* Got to be a CONNECT msg */
- {
- if (strnicmp(response,"connect",7) == 0)/* if this is a CONNECT, */
- {
- c = skip_blanks(&response[7]); /* get past the blanks */
- if (*c == '\0') /* if nothing there, */
- set_baud(300,1); /* say that it's 300 baud */
- else
- set_baud(atoi(c),1); /* else do baudrate fallback */
- }
- }
-
- return (result == SUCCESS); /* timeout or failure or OK */
- }
-
- mdm_cmd_string(mdm_cmd,dospace)
- char *mdm_cmd;
- int dospace;
- {
- register char *c;
- for (c = mdm_cmd; *c; c++)
- {
- if (dospace || !isspace(*c)) /* don't output spaces */
- mdm_cmd_char(*c); /* output the next character */
- }
- }
-
- empty_delay ()
- {
- long t, timerset ();
-
- t = timerset (500);
- while ((!OUT_EMPTY()) && (!timeup(t)))
- time_release(); /* wait for output to finish */
- if (!OUT_EMPTY())
- {
- status_line ("!Timeout waiting for output to clear");
- MDM_DISABLE();
- Cominit(port_ptr);
- MDM_ENABLE(btypes[baud].rate);
- DTR_ON();
- CLEAR_OUTBOUND();
- CLEAR_INBOUND();
- }
- }
-
- mdm_cmd_char(outchr)
- char outchr;
- {
-
- if (outchr == '\-') /* if it's a dash (phone no) */
- return; /* ignore it */
-
- if (outchr == '\|') /* if the CR character, */
- outchr = CR; /* substitute a real CR here */
-
- if (outchr == '.') /* Substitute ',' for '.' for compatibility */
- outchr = ',';
-
- if (outchr == '\~') /* if the "delay" character, */
- {
- empty_delay ();
- timer(10); /* then wait 1 second */
- return; /* and return */
- }
-
- if (outchr == '^') /* Raise DTR */
- {
- empty_delay ();
- DTR_ON ();
- return;
- }
-
- if (outchr == 'v') /* Lower DTR */
- {
- empty_delay ();
- DTR_OFF ();
- return;
- }
-
- if (outchr == '`') /* Short delay */
- {
- timer(1); /* short pause, .1 second */
- return;
- }
-
- SENDBYTE(outchr); /* then write the character */
-
- if (outchr == CR) /* if it was a CR, */
- {
- empty_delay ();
- timer(1); /* allow .1 sec line quiet */
- }
- else if (slowmodem)
- {
- timer(1); /* wait .1 sec for output */
- }
- }
-
- mdm_hangup()
- {
- /* First, if a dial command is in progress,
- try to get the modem to abort it... */
-
- CLEAR_OUTBOUND();
- CLEAR_INBOUND();
-
- if (un_attended && fullscreen)
- {
- gotoxy (69, 7);
- cprintf ("%-2d HangUp ", cur_event + 1);
- }
- else
- {
- status_line("#Modem hang up sequence"); /* Tell what we are doing */
- }
-
- mdm_init(ctl.m_init); /* re-initialize the modem */
-
- DTR_OFF(); /* Then turn off DTR again */
- timer(5); /* And hold for .5 sec more */
-
- DTR_ON(); /* Raise it, */
- mdm_cmd_char(CR); /* then another CR */
- set_xy("");
- mdm_cmd_char(CR); /* then another CR */
- CLEAR_INBOUND(); /* then flush input and exit */
- }
-
- mdm_init(str)
- {
- CLEAR_OUTBOUND();
- CLEAR_INBOUND();
- mdm_cmd_char(CR); /* output a CR, then */
- DTR_OFF(); /* Drop DTR to hangup */
- timer(10); /* Hold it down for 1 sec */
-
- DTR_ON(); /* Raise DTR, */
- timer(5); /* Then hold it up for .5 sec*/
- set_baud (ctl.max_baud, 0);
-
- mdm_cmd_char(' '); /* output a space */
- mdm_cmd_char(CR); /* then another CR */
- mdm_cmd_string(str,0); /* then the modem init string*/
- timer(5); /* Hold DTR for .5 sec more */
- CLEAR_INBOUND(); /* then flush input and exit */
- }